/* Copyright (C) 2010 Luca Piccinelli
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "prj_definitions.h"
#include "generators/resource/AbstractResourceGenerator.h"

#include <string>

using namespace std;

namespace NAMESPACE{

AbstractResourceGenerator::~AbstractResourceGenerator(){}

AbstractResourceGenerator::AbstractResourceGenerator() : AbstractGenerator(),
                                                         resource(),
                                                         is_open(false){}
AbstractResourceGenerator::AbstractResourceGenerator(const AbstractResourceGenerator& g) 
                                                     : AbstractGenerator(g),
                                                       resource(g.resource),
                                                       is_open(false){}
AbstractResourceGenerator& AbstractResourceGenerator::operator=(const AbstractResourceGenerator& g){
    if(this == &g) return *this;

    AbstractGenerator::operator =(g);

    if(is_open) close();
    resource = g.resource;

    return *this;
}

AbstractResourceGenerator::AbstractResourceGenerator(const string& _resource,
                                                     const memory_size_t& _max_mem)
                                                     : AbstractGenerator(_max_mem),
                                                       resource(_resource),
                                                       is_open(false){}
AbstractResourceGenerator::AbstractResourceGenerator(const IOKey& k, 
                                                     const memory_size_t& _max_mem)
                                                     : AbstractGenerator(k, _max_mem),
                                                       resource(),
                                                       is_open(false){}
AbstractResourceGenerator::AbstractResourceGenerator(const string& _resource,
                                                     const IOKey& k,
                                                     const memory_size_t& _max_mem)
                                                     : AbstractGenerator(k, _max_mem),
                                                       resource(_resource),
                                                       is_open(false){}

AbstractResourceGenerator& AbstractResourceGenerator::set_resource(const string& _resource){
    if(is_open) close();
    resource = _resource;
    return *this;
}

bool AbstractResourceGenerator::is_opened() const{
        return is_open;
    }
}
